import Vue from 'vue'
import Vuex from 'vuex'
import Login from './modules/login.js'
import PageForm from './modules/page_form.js'
import PageList from './modules/page_list.js'
import Navi from './modules/navi.js'
import Message from './modules/message.js'
import ExamPaper from './modules/exam/paper.js'
import Website from './modules/website.js'

Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    isLoading: false, // 控制显示加载层,有300毫秒延迟
    loadingStatus: false, // 加载状态,及时性
    timer: 0
  },
  mutations: {
    SET_LOADING_STATUS: (state, status) => {
      clearTimeout(state.timer);
      state.loadingStatus = status;
      if (status) {
        state.timer = setTimeout(() => {
          state.isLoading = true
        }, 300)
      } else {
        state.isLoading = false
      }
    }
  },
  actions: {
    setLoading({
      commit
    }, status) {
      commit('SET_LOADING_STATUS', status)
    }
  },
  modules: {
    login: Login,
    pageForm: PageForm,
    pageList: PageList,
    navi: Navi,
    message: Message,
    examPaper: ExamPaper,
    website: Website
  }
})
export default store
